package com.share.tx.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.share.tx.dao.AccountAMapper;
import com.share.tx.dao.AccountBMapper;
import com.share.tx.entity.AccountA;
import com.share.tx.entity.AccountB;

@Service
public class AccountABService {
	
	@Autowired
	AccountAService accountAService;
	
	@Autowired
	AccountBService accountBService;
	
	@Autowired
	AccountAMapper accountAMapper;
	
	@Autowired
	AccountBMapper accountBMapper;
	
	
//	@Transactional(propagation = Propagation.REQUIRES_NEW)
	public void compoundOpt(AccountB accountB, AccountA accountA) throws InterruptedException{
		accountAService.insertAccountA(accountA);
//		try {
//			accountBService.insertAccountB(accountB);
//		} catch (Exception e) {
//			System.out.println("回滚");
//		}
		int i=1/0;
//		Thread.sleep(1000000);
		accountBService.insertAccountB(accountB);
//		int i = 1/0;
		
		
		
//		accountAMapper.insertAccountA(accountA);
//		int i=1/0;
//		accountBMapper.insertAccountB(accountB);
		
	}
	
	
	public void compoundOpt1(AccountB accountB1, AccountB accountB2){
		accountBService.updateMoneyByAccountB1(accountB1);
		accountBService.updateMoneyByAccountB1(accountB2);
		
//		try {
//			Thread.sleep(30000);
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}

	}
	
}
